var vm = new Vue({
	el: ".content",
	data: {
		flowers: [],
		bookdata: "",
		mark: '',
		pingfen: '',
		data: "",
		state: ""
	},
	updated: function() {
	}
})

if(localStorage.getItem("state") == "true") {
	vm.state = true
} else {
	vm.state = false
}


var temp = 1

function refresh() {
	temp = 1
	vm.flowers = []
	mui('#pullrefresh').pullRefresh().refresh(true);
	shuaxin()
}

//打开评论
/*$(".translate").on("tap", function() {
	mui.openWindow({
		url: 'comment.html',
		id: "comment.html"
	})
	setTimeout(function() {
		mui.currentWebview.hide('none');
	}, 300);
})*/
mui.init({
	pullRefresh: {
		container: '#pullrefresh',
		up: {
			contentrefresh: '正在加载...',
			callback: pullupRefresh
		}
	}
});

function parent(id) {
	console.log(id)
	$(".content").attr("uid", id)
	common.ajax('teacher/bookCity/' + id, {
		token: common.token,
		uid: common.uid,
		bookUid: id
	}, function(data) {
		if(data.code == 200) {
			vm.bookdata = data.data
			if(String(data.data.mark).indexOf(".") != -1) {
				vm.pingfen = true
			}
			vm.mark = Math.floor(data.data.mark)
			vm.data = data.data
			//			joinissue()
		} else {
			mui.toast(data.message)
		}
	})
	shuaxin()
	$(".translate").on("tap", function() {
		common.open("comment.html", "comment.html", id)
	})
}

function shuaxin() {
	if(mui.os.plus) {
		mui.plusReady(function() {
			setTimeout(function() {
				mui('#pullrefresh').pullRefresh().pullupLoading();
			}, 300);

		});
	} else {
		mui.ready(function() {
			mui('#pullrefresh').pullRefresh().pullupLoading();
		});
	}
}

/**
 * 下拉刷新具体业务实现
 */
/*function pulldownRefresh() {
	setTimeout(function() {
		mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); //refresh completed
	}, 400);
}*/
/**
 * 上拉加载具体业务实现
 */

function pullupRefresh() {
	common.ajax("book/queryBookComment", {
		uid: common.uid,
		token: common.token,
		bookUid: $(".content").attr("uid"),
		page: temp++,
		pageSize: 8
	}, function(data) {
		if(data.code == 200) {
			//				vm.flowers =[]
			if(!data.data.hasNextPage) {
				mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
			} else {
				mui('#pullrefresh').pullRefresh().endPullupToRefresh();
			}

			for(var i = 0; i < data.data.list.length; i++) {

				vm.flowers.push(data.data.list[i])
			}
		} else {
			mui.toast(data.message)
		}
		//参数为true代表没有更多数据了。
	}, "get")
}